home *** CD-ROM | disk | FTP | other *** search
- /*
- IC Movable Modal.c
-
- This code implements a MovableModalDialog routine similar to the
- Toolbox routine ModalDialog, to be used for movable modal dialogs.
-
- Based on code by Merzwaren (piovanel@dsi.unimi.it)
-
- */
-
- #include <GestaltEqu.h>
- #include <LowMem.h>
- #include <Traps.h>
- #include <Packages.h>
- #include <Dialogs.h>
- #include <Balloons.h>
-
- #include "IC Types.h"
- #include "IC Dialogs.h"
- #include "IC Globals.h"
- #include "IC Misc Subs.h"
- #include "IC Movable Modal.h"
-
- #include "Call68kGlue.h"
-
- void DisableMenuBar(Ptr* saved_state,short hmnuID){
- MenuListHandle menuList;
- short i,nMenus;
- MenuHandle theMenu;
- short menuID;
- DialogPtr theDialog;
- Boolean hasBalloons=Has_HelpMgr,needEditMenu;
- MenuBarStatePtr state;
-
- theDialog=FrontWindow();
- needEditMenu=((theDialog!=(DialogPtr)0)&&(SelectedTextItem(theDialog)>0));
-
- menuList=(MenuListHandle)LMGetMenuList();
- nMenus=(*menuList)->offsetToLastMenu/sizeof(MenuEntry);
-
- *saved_state=NewPtr(sizeof(MenuBarState));
- state=(MenuBarStatePtr)*saved_state;
-
- state->mbsBarEnable=0;
-
- for (i=0;i<nMenus;i++){
- theMenu=(*menuList)->theMenus[i].hMenu;
- menuID=(*theMenu)->menuID;
-
- if (menuID>kSystemMenuThreshold){ // do nothing if this is a system menu
- if (menuID==M_Edit){
- state->mbsEditEnable=(*theMenu)->enableFlags;
- if (needEditMenu)
- (*theMenu)->enableFlags=1+(1<<EM_Cut)+(1<<EM_Copy)+(1<<EM_Paste);
- else
- DisableItem(theMenu,0);
- } else { // if this menu is enabled, disable it and set the corresponding bit
- if ((*theMenu)->enableFlags&(1<<0)){
- state->mbsBarEnable |= (1<<i);
- DisableItem(theMenu,0);
- }
-
- if (hasBalloons){ // remap the help strings for this menu
- HMSetMenuResID(menuID,hmnuID);
- }
- }
- }
- }
-
- HiliteMenu(0);
- DrawMenuBar();
- }
-
- void ReEnableMenuBar(Ptr* saved_state){
- MenuListHandle menuList;
- short i,nMenus;
- MenuHandle theMenu;
- short menuID;
- Boolean hasBalloons=Has_HelpMgr;
- OSErr err;
- MenuBarStatePtr state=(MenuBarStatePtr)*saved_state;
-
- menuList=(MenuListHandle)LMGetMenuList();
- nMenus=(*menuList)->offsetToLastMenu/sizeof(MenuEntry);
-
- for (i=0;i<nMenus;i++){
- theMenu=(*menuList)->theMenus[i].hMenu;
- menuID=(*theMenu)->menuID;
-
- if (menuID>kSystemMenuThreshold){
- if (menuID==M_Edit)
- (*theMenu)->enableFlags=state->mbsEditEnable;
- else if (state->mbsBarEnable&(1<<i))
- EnableItem(theMenu,0);
-
- if (hasBalloons)
- HMSetMenuResID(menuID,-1);
- }
- }
-
- DisposePtr(*saved_state);
- *saved_state=(Ptr)0;
-
- DrawMenuBar();
- }
-
- pascal void CallBeeper(short soundNo,BeeperUPP beeperProc){
-
- CallBeeperProc(beeperProc,soundNo);
- }
-
- Boolean DoMenuChoice(DialogPtr theDialog,EventRecord* er,short* itemHit,long menuChoice){
- short menuID,menuItem;
- short currentEditField,itemType;
- Boolean res=false;
-
- menuID=HiWord(menuChoice);
- menuItem=LoWord(menuChoice);
-
- if (menuID==M_Edit){
- currentEditField=SelectedTextItem(theDialog);
- GetDItemKind(theDialog,currentEditField,&itemType);
-
- if ((itemType&itemDisable)==0){
- // if the current edit field is an enabled item, exit from MovableModalDialogLoop
- *itemHit=currentEditField;
- res=true;
-
- if (menuItem==EM_Cut){
- DialogCut(theDialog);
- ZeroScrap();
- TEToScrap();
- } else if (menuItem==EM_Copy){
- DialogCopy(theDialog);
- ZeroScrap();
- TEToScrap();
- } else if (menuItem==EM_Paste){
- TEFromScrap();
- DialogPaste(theDialog);
- }
- }
- }
- HiliteMenu(0);
-
- return res;
- }
-
- Boolean HandleMouseDown(DialogPtr theDialog,EventRecord* theEvent,short* itemHit){
- short partCode;
- WindowPtr wind;
- BeeperUPP beeper;
- Rect dragRect;
- Boolean res=false;
-
- partCode=FindWindow(theEvent->where,&wind);
-
- if (partCode==inMenuBar)
- res=DoMenuChoice(theDialog,theEvent,itemHit,MenuSelect(theEvent->where));
- else if (!PtInRgn(theEvent->where,((WindowPeek)theDialog)->strucRgn)){
- beeper=(BeeperUPP)LMGetDABeeper();
- if (beeper!=(BeeperUPP)0)
- CallBeeperProc(beeper,1);
- } else if ((partCode==inDrag)&&(theDialog==wind)){ // now we have to handle the only thing dialog select doesn't do for us: dragging
- RgnHandle rgn=GetGrayRgn();
-
- dragRect=(*rgn)->rgnBBox;
- DragWindow(wind,theEvent->where,&dragRect);
- theEvent->what=nullEvent;
- }
-
- return res;
- }
-
- void MovableModalDialog(ModalFilterUPP filterProc,short* itemHit){
- DialogPtr theDialog,junk;
- EventRecord theEvent;
- Boolean gotEvent;
-
- *itemHit=0;
- theDialog=(DialogPtr)FrontWindow();
- if (theDialog!=(DialogPtr)0){
- SetPort(theDialog);
- do {
- gotEvent=WaitNextEvent(kMovableModalEventMask,&theEvent,0,(RgnHandle)0);
- SetPort(theDialog);
-
- if ((filterProc!=(ModalFilterUPP)0)&&CallModalFilterProc(filterProc,theDialog,&theEvent,itemHit))
- return;
-
- if ((theEvent.what==mouseDown)&&HandleMouseDown(theDialog,&theEvent,itemHit))
- return;
-
- if ((theEvent.what==keyDown)&&((theEvent.modifiers&cmdKey)!=0)&&
- DoMenuChoice(theDialog,&theEvent,itemHit,MenuKey(theEvent.message&charCodeMask)))
- return;
-
- if ((IsDialogEvent(&theEvent))&&(DialogSelect(&theEvent,&junk,itemHit)))
- return;
- } while (1);
- }
- }
-
-
-
-